class Game{
	constructor(bg_music){
		// 构造函数
		this.init();
    this.play_music(bg_music);
	}
	open(){

	}
	init(){
		// 初始化
		console.log("系统初始化");
    this.rem();
	}
	print(data){
		// 打印数据
		console.log(JSON.stringify(data));
	}
	back(prev){
		// 返回上一页
		this.go(prev.name,prev.url,{...prev});
	}
	go(name,url,pageParam){
		this.print(name)
		this.print(url)
		this.print(pageParam)
		// 跳转到指定页面
		api.openFrame({
				name: name,
				url: url,
				rect: {
						x: 0,
						y: 0,
						w: 'auto',
						h: 'auto'
				},
				useWKWebView:true,
				historyGestureEnabled:true,
				bounces:false,
				animation:{
							type:"push",
							subType:"from_right",
							duration:300
				},
				pageParam: pageParam
		});
	}
  rem(){
    if(window.innerWidth<1200){
			this.UIWidth = document.documentElement.clientWidth;
      this.UIHeight = document.documentElement.clientHeight;
      document.documentElement.style.fontSize = (0.01*this.UIWidth*3)+"px";
			document.querySelector("#app").style.height=this.UIHeight+"px"
    }
    window.onresize = ()=>{
      if(window.innerWidth<1200){
        this.UIWidth = document.documentElement.clientWidth;
        this.UIHeight = document.documentElement.clientHeight;
        document.documentElement.style.fontSize = (0.01*this.UIWidth*3)+"px";
      }
    }
  }
	bg(){
		// 背景

	}
	music(){

	}
	stop_music(){
		this.print("停止")
		document.body.removeChild(this.audio);
	}
  play_music(src){
    this.audio = document.createElement("audio");
    this.source = document.createElement("source");
    this.source.type = "audio/mp3";
    this.audio.autoplay = "autoplay";
    this.source.src=src;
    this.audio.appendChild(this.source);
    document.body.appendChild(this.audio);
    var t = setInterval(()=>{
      if(this.audio.readyState > 0){
        if(this.audio.ended){
          clearInterval(t);
          document.body.removeChild(this.audio);
        }
      }
    },100);
  }
}
